//
//  GFriestLevelView.m
//  helpinrain
//
//  Created by Gang.Wang on 12-7-26.
//  Copyright (c) 2012年 Zhuhai Yuike Technology Co., Ltd. All rights reserved.
//

#import "GFriestLevelView.h"
#import "mcf.h"

@interface GFriestLevelView ()
{
    UIButton * firstSheetButton_;
    UIButton * secondSheetButton_;
    
    UIButton * thridSheetButton_;
}

@property (nonatomic, strong) UIButton * firstSheetButton;
@property (nonatomic, strong) UIButton * secondSheetButton;

@property (nonatomic, strong) UIButton * thridSheetButton;

- (void) privateInit;

@end

@implementation GFriestLevelView



@synthesize firstSheetButton = firstSheetButton_;
@synthesize secondSheetButton = secondSheetButton_;

@synthesize thridSheetButton = thridSheetButton_;
@synthesize delegate = delegate_;


- (void) dealloc
{
    YRelease(firstSheetButton_)
    YRelease(secondSheetButton_)
    
    YRelease(thridSheetButton_)
    
    [super dealloc];
}

- (id) init
{
    self = [super init];
    if (self) 
    {
        [self privateInit];
    }
    
    return self;
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self privateInit];
    }
    return self;
}


- (void) privateInit
{
    if (self.bInited) 
    {
        return;
    }
    
    self.firstSheetButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.firstSheetButton setBackgroundColor:RGB(235, 235, 235)];
    [self.firstSheetButton setTitle:@"雨中" forState:UIControlStateNormal];
    [[self.firstSheetButton titleLabel] setFont:[UIFont fontWithName:@"Helvetica-Bold" size: isPad ? 66 : 40]];
    self.firstSheetButton.tag = 1;
    [self addSubview:self.firstSheetButton];
    BUTTON_FUNCTION(self.firstSheetButton, openMagazine:)
    
    
    self.secondSheetButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.secondSheetButton setBackgroundColor:RGB(235, 235, 235)];
    [self.secondSheetButton setTitle:@"雨后" forState:UIControlStateNormal];
    [[self.secondSheetButton titleLabel] setFont:[UIFont fontWithName:@"Helvetica-Bold" size:isPad ? 66 : 40]];
    self.secondSheetButton.tag = 2;
    [self addSubview:self.secondSheetButton];
    BUTTON_FUNCTION(self.secondSheetButton, openMagazine:)
    
    self.thridSheetButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.thridSheetButton setBackgroundColor:COLOR_MAGENTA];
    [self.thridSheetButton setTitle:@"BUTTON3" forState:UIControlStateNormal];
    self.thridSheetButton.tag = 3;
    [self addSubview:self.thridSheetButton];
    BUTTON_FUNCTION(self.thridSheetButton, openMagazine:)
    
    
    [self reAdjustLayout];
    self.bInited = TRUE;
}

- (void) openMagazine:(id) sender
{
    NSString * sheetName = nil;
    
    int tag = [(UIView *) sender tag];
    switch (tag) {
        case 1:
            sheetName = @"sheet1.xml";
            break;
            
        case 2:
            sheetName = @"sheet2.xml";
            break;
            
        case 3:
            sheetName = @"sheet3.xml";
            break;
            
        default:
            break;
    }
    
    DELEGATE_CALLBACK(openSheet:, sheetName)
    
}

- (void) reAdjustLayout
{
    CGRect frame = CGRectMake(20,
                              50,
                              self.width - 40,
                              (self.height - 100) / 2 - 10);
    
    [self.firstSheetButton setFrame:frame];
    
    [self.secondSheetButton setFrame:CGRectMake(20,
                                                self.firstSheetButton.frame.origin.y + self.firstSheetButton.frame.size.height + 5,
                                                self.width - 40, 
                                                (self.height - 100) / 2 - 10)];
    
    return;
    
    [self.thridSheetButton setFrame:CGRectMake(20, 
                                               self.secondSheetButton.frame.origin.y + self.secondSheetButton.frame.size.height, 
                                               self.width - 40, 
                                               (self.height - 100) / 3)];
    
}

- (void) setFrame:(CGRect)frame
{
    [super setFrame:frame];
    [self reAdjustLayout];
}

@end
